<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>附属设备列表</title>
    <!-- css代码 start -->
    <link href="../../../../../css/mui.min.css" rel="stylesheet"/>
    <link href="../../../../../css/global.css" rel="stylesheet"/>
    <link href="../../../../../css/style.css" rel="stylesheet"/>
    <link href="../../../../../css/task.css" rel="stylesheet"/>
    <style>
        #div {
            width: 0px;
            height: 0px;
            background: red;
            position: fixed;
            top: 65%;
            left: 50%;
        }

        /*移除底部或顶部三角,需要在删除此代码*/
        .mui-popover .mui-popover-arrow:after {
            width: 0px;
        }

        .item_box .item .name {
            font-weight: inherit;
        }
    </style>
    <!-- css代码 end -->
</head>
<body>
<!-- html代码 start -->
<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 id="title" class="mui-title">附属设备列表</h1>
</header>
<div class="mui-content">
    <div hidden>
        <input type="hidden" id="ServiceNoticeId"/>
        <input type="hidden" id="instrumentNo"/>
        <input type="hidden" id="serviceNoV"/>
    </div>
    <div id="div"></div>
    <div id="popover" class="mui-popover shadow popover">
        <p class="title">确定要删除吗?</p>
        <div class="btn_box">

            <span class="fl" onclick="closepop()">取消</span>
            <span class="fr red" id="queding">确定</span>
        </div>
    </div>
    <div class="item_box" id="liebiao">
        <!-- <div class="item" >
            <p class="bar"><span class="number">1170001<img src="../../../../../images/icon_3.png" /></span><span class="del">删除</span></p>
            <div class="text">附件名称<span>121212</span></div>
            <div class="text">附件序列号<span>2312323</span></div>
            <div class="text">保修开始时间<span>23424234</span></div>
            <div class="text">保修结束时间<span>23424234</span></div>
        </div>
        <div class="item" >
            <p class="bar"><span class="number">1170001<img src="../../../../../images/icon_3.png" /></span><span class="del">删除</span></p>
            <div class="text">附件名称<span>121212</span></div>
            <div class="text">附件序列号<span>2312323</span></div>
            <div class="text">保修开始时间<span>23424234</span></div>
            <div class="text">保修结束时间<span>23424234</span></div>
        </div> -->
    </div>
	<div class="btn_box">
		<span id="tjfssb" class="fl red one">添加附属设备</span>
	</div>
</div>
<!-- html代码 end -->

<!-- js代码 start -->

<!-- 基础js start -->
<script src="../../../../../js/mui.min.js"></script>
<script src="../../../../../js/utils/h.js"></script>
<script src="../../../../../js/constant.js"></script>
<script src="../../../../../js/common.js"></script>
<script src="../../../../../js/utils/base64.js"></script>
<script src="../../../../../js/utils/md5.js"></script>
<script src="../../../../../js/utils/sortMap.js"></script>
<script src="../../../../../js/utils/http.js"></script>
<script src="../../../../../js/app.js"></script>
<!-- 基础js end -->

<script type="text/javascript" charset="utf-8">
    var id;
    // 提交状态 0未提交 1已提交
    var submitStatus = 0;
    (function ($, doc) {
        $.init();

        $.plusReady(function () {
            var self = plus.webview.currentWebview();
            submitStatus = self.submitStatus
            submitStatus = self.submitStatus
            if (submitStatus && submitStatus == '1') {
                h('#tjfssb').hide()
            }
            // 获取上一个页面传过来的参数并显示到页面
            h('#serviceNoV').val(self.serviceNo);
            h('#ServiceNoticeId').val(self.ServiceNoticeId);
            h('#instrumentNo').val(self.instrumentNo);

            initData()


            h("#tjfssb").tap(function () {
                app.jumpTo("/view/service/report/installationquality/accessoryEquipment/add.html", "view/service/report/installationquality/accessoryEquipment/add.html",
                    {
                        ServiceNoticeId: h("#ServiceNoticeId").val(),
                        serviceNo: h("#serviceNoV").val(),
                        instrumentNo: h("#instrumentNo").val(),
                        addType: 1
                    })
            })
            // 确定删除
            h("#queding").tap(function () {
                mui("#popover").popover('toggle', document.getElementById("div"));
                app.showWaiting('删除中...')
                ajaxGet(BASE_URL + "cc/installation/quality/report/removeEquipmentAccessory", {
                    "instrumentNo": h("#instrumentNo").val(),
                    "enginnerId": app.getUser().enginnerId,
                    "serviceNo": h("#serviceNoV").val(),
                    "assetNo": id
                }, function (data) {
                    app.closeWaiting()
                    console.log(JSON.stringify(data))
                    if (data.code == 200) {
                        app.toast("删除成功")

                    } else {
                        app.toast("删除失败")
                    }
                    initData()
                }, function (errorMsg) {
                    app.closeWaiting()
                    console.log(JSON.stringify(errorMsg))
                    app.toast(JSON.stringify(errorMsg))
                });

            })

        });
    }(mui, document));

    // 列表查询
    function initData() {
        ajaxGet(BASE_URL + "cc/installation/quality/report/selectEquipmentAccessorys", {
            "instrumentNo": h("#instrumentNo").val(),
            "enginnerId": app.getUser().enginnerId,
            "serviceNo": h("#serviceNoV").val()
        }, function (data) {
            console.log(JSON.stringify(data))
            if (data.code == 200) {
                h("#liebiao").html("");
                var html = "";
                if (data.data && data.data.length > 0) {
                    for (var i = 0; i < data.data.length; i++) {
                        var das = data.data[i];
                        var ASSET_SN = das.ASSET_SN == undefined ? "无" : das.ASSET_SN;
                        var ASSET_NAME = das.ASSET_NAME == undefined ? "无" : das.ASSET_NAME;
                        var ASSET_NO = das.ASSET_NO == undefined ? "无" : das.ASSET_NO;
                        var Asset_WarrantyStart = das.Asset_WarrantyStart == undefined ? "无" : das.Asset_WarrantyStart;
                        var Asset_WarrantyEnd = das.Asset_WarrantyEnd == undefined ? "无" : das.Asset_WarrantyEnd;
                        html += '<div class="item" >'
                        html += '<p class="bar"><span class="number">' + ASSET_SN + '<img src="../../../../../images/icon_204.png" /></span><span class="del" onclick=shanchu(\'' + ASSET_NO + '\')>删除</span></p>'
                        html += '<div class="name">附件名称：<span>' + ASSET_NAME + '</span></div>'
                        html += '<div class="name">保修开始时间：<span>' + Asset_WarrantyStart + '</span></div>'
                        html += '<div class="name">保修结束时间：<span>' + Asset_WarrantyEnd + '</span></div>'
                        html += '</div>';
                    }
                    h("#liebiao").html(html);
                    if (submitStatus == '1') {
                        h('.del').hide()
                    }
                } else {
                    var html = '<div class="nodata">—— 暂无数据 ——</div>';
                    h("#liebiao").html(html);
                }
            } else {
                var html = '<div class="nodata">—— 暂无数据 ——</div>';
                h("#liebiao").html(html);
				app.toast(data.msg);
            }
        }, function (errorMsg) {
			var html = '<div class="nodata">—— 暂无数据 ——</div>';
			h("#liebiao").html(html);
			app.toast("数据获取失败，请检查网络连接");
        });
    }


    // 删除方法
    function shanchu(ASSET_NO) {
        id = ASSET_NO;
        mui("#popover").popover('toggle', document.getElementById("div"));
    }

    // 取消删除
    function closepop() {
        mui("#popover").popover('toggle', document.getElementById("div"));
    }

</script>
<!-- js代码 end -->
</body>
</html>
